﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPPD.model;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Linq;

namespace SPPD.controller
{
    class controller_sppd
    {
        crud <sppd> nhi;
        List <sppd> sppdlist;
        public controller_sppd()
        {
            nhi = new crud<sppd>();
            sppdlist = new List<sppd>();
        }
        public void insert(sppd sppd)
        {
            nhi = new crud<sppd>();
            nhi.insert(sppd);
        }
        public List<sppd> load()
        {
            var factory = nhi.load();
            using (var session = factory.OpenSession())
            {
                var categories = session.Query<sppd>()
                       .ToList();
                return categories;
            }
        }

        public void update(sppd sppd_update)
        {
            var factory = nhi.load();
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var categories = session.Get<sppd>(sppd_update.id_sppd);
                    categories.status += 1;
                    transaction.Commit();
                }
                
                
                
            }
        }
        public string autogenerate()
        {
            sppdlist = load();
            return "SP" + (sppdlist.Count + 1);
        }

        public string autogenerateSPJ()
        {
            sppdlist = load();
            return "SJ" + (sppdlist.Count + 1);
        }
    }
}
